package personal.wang.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import personal.wang.config.DataMockYamlReader;
import personal.wang.constant.AppConstant;

import java.io.File;
import java.util.*;

/**
 * @className: GenerateJob
 * @Description:
 * @Author: wangyifei
 * @Date: 2022/6/16 16:55
 */
public class GenerateJob {
//    private static Logger logger = LoggerFactory.getLogger(GenerateJob.class);
//    private static final String CONFIG_PATH_NAME = "config_path" ;
//    private static final String IS_ACTIVE_TAG_NAME = "is_active" ;
//    private static final String PRODUCER_TYPE_TAG_NAME = "kafka.producer_type" ;
//    private List<TestPoint> testPoints = new ArrayList<>();
//    private static String COMMON_CONFIG_BASE_PATH_TAG_NAME = "common_config.base_path";
//    private static String TEST_POINT_TAG_NAME = "test_points";
//    private static String PACKAGE_TAG_NAME = "pkg";
//    private static String DICTIONARY_PACKAGE_TAG_NAME = "dictionary";
//    private static String TEMPLATE_PACKAGE_TAG_NAME = "tpl";
//    private static String SEND_RECORD_BATCH_TAG_NAME = "batch_size";
//    private static String PRODUCER_NUMBER_TAG_NAME = "producer_num" ;
//    private static String KAFKA_BOOTSTRAP_TAG_NAME = "kafka.bootstrap" ;
//    private static String KAFKA_TOPIC_TAG_NAME = "kafka.topic_name" ;
//    private static String BACKUP_PATH_TAG_NAME = "backup_path" ;
//    private static String SEND_MESSAGE_NUMBER_TAG_NAME = "msg_num" ;
//    private static String ACTIVE_TAG_NAME = "true" ;
//    private static String TABLE_NAME_TAG_NAME = "table_name" ;
//
//    public void init(String path){
//        String basePath = DataMockYamlReader.getValueAsString(path , COMMON_CONFIG_BASE_PATH_TAG_NAME);
//        Map testPoints = DataMockYamlReader.getValueAsMap(path , TEST_POINT_TAG_NAME);
//        Set set = testPoints.entrySet();
//        Map.Entry entry = null ;
//        TestPoint testPoint = null ;
//        for (Object o : set) {
//           if(o instanceof Map.Entry) {
//               entry = (Map.Entry)o ;
//               testPoint = new TestPoint();
//               Object value = entry.getValue();
//               if(value instanceof Map){
//                   Map map = (Map<? , ?>)value ;
//
//                   if(!ACTIVE_TAG_NAME.equals(map.get(IS_ACTIVE_TAG_NAME).toString())){
//                       continue;
//                   }
//                   testPoint.setTableName(map.get(TABLE_NAME_TAG_NAME).toString());
//                   testPoint.setPath(basePath + map.get(PACKAGE_TAG_NAME).toString());
//                   testPoint.setDicPath(testPoint.getPath() + File.separator + DICTIONARY_PACKAGE_TAG_NAME);
//                   testPoint.setTplPath(testPoint.getPath() + File.separator + TEMPLATE_PACKAGE_TAG_NAME);
//                   testPoint.setBatchSize((Integer)map.get(SEND_RECORD_BATCH_TAG_NAME));
//                   String bootstrap = DataMockYamlReader.getValueAsString(path , TEST_POINT_TAG_NAME
//                           + AppConstant.DOT + entry.getKey() + AppConstant.DOT + KAFKA_BOOTSTRAP_TAG_NAME);
//                   String topics = DataMockYamlReader.getValueAsString(path , TEST_POINT_TAG_NAME
//                           + AppConstant.DOT + entry.getKey() + AppConstant.DOT + KAFKA_TOPIC_TAG_NAME);
//                   String producerType = DataMockYamlReader.getValueAsString(path , TEST_POINT_TAG_NAME
//                           + AppConstant.DOT + entry.getKey() + AppConstant.DOT + PRODUCER_TYPE_TAG_NAME);
//                   testPoint.setKafkaBootstrap(bootstrap);
//                   testPoint.setProducerType(producerType);
//                   testPoint.setTopicNames(topics.split(AppConstant.COMMA));
//                   testPoint.setMsgNumber((Integer)map.get(SEND_MESSAGE_NUMBER_TAG_NAME));
//                   testPoint.setName((String)map.get(PACKAGE_TAG_NAME));
//                   testPoint.setProducerNumber((Integer)map.get(PRODUCER_NUMBER_TAG_NAME));
//                   testPoint.setBackupPath(basePath + map.get(BACKUP_PATH_TAG_NAME).toString());
//                   testPoint.setSummaryPath(testPoint.getPath());
//                   this.testPoints.add(testPoint);
//               }
//           }
//        }
//    }
//
//    public static void main(String[] args) {
//        GenerateJob gj = new GenerateJob();
//        Properties properites = new Properties();
//        for(int i = 0 ; i < args.length ; i++){
//            if(i+1 < args.length && "--".concat(CONFIG_PATH_NAME).equals(args[i+1])){
//                properites.put(CONFIG_PATH_NAME , args[i+1]);
//            }
//        }
//        gj.init((String) properites.get(CONFIG_PATH_NAME));
//        long start = System.currentTimeMillis();
//        gj.execute();
//        logger.info("the duration is : %s" , System.currentTimeMillis() - start);
//    }
//    public void execute(){
//        for (TestPoint testPoint : this.testPoints) {
//             testPoint.execute();
//        }
//    }

}
